// 防抖：n 秒后只执行一次，期间再次触发会重新计时
export function debounce(fn, delay = 300) {
    let timer = null;
    return function (...args) {
      if (timer) clearTimeout(timer);
      timer = setTimeout(() => {
        fn.apply(this, args);
      }, delay);
    };
  }
  
  // 节流：n 秒内只执行一次
  export function throttle(fn, delay = 300) {
    let last = 0;
    return function (...args) {
      const now = Date.now();
      if (now - last > delay) {
        last = now;
        fn.apply(this, args);
      }
    };
  }
